/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package com.qingyan.flink.core.source.cdc;

import com.qingyan.flink.core.Schema;
import com.qingyan.flink.core.Table;
import com.qingyan.flink.core.matedata.Driver;
import com.qingyan.flink.core.model.SchemaMapping;
import com.qingyan.flink.core.properties.FlinkDataSourceProperties;
import com.qingyan.flink.core.properties.FlinkTransProperties;
import com.qingyan.flink.core.sink.SinkBuilder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * AbstractCDCBuilder
 *
 * @author wenmo
 * @since 2022/11/04
 **/
public abstract class AbstractCDCBuilder implements CDCBuilder {

    protected FlinkDataSourceProperties dataSourceProperties;
    protected FlinkTransProperties transProperties;
    protected Map<String, String> sourceConfig;
    protected List<Schema> schemaList;
    protected Driver driver;

    public AbstractCDCBuilder() {
    }

    @Override
    public AbstractCDCBuilder create(FlinkDataSourceProperties dataSourceProperties, FlinkTransProperties transProperties) {
        this.dataSourceProperties = dataSourceProperties;
        this.transProperties = transProperties;
        this.sourceConfig = transProperties.getSourceConfig();
    }


    public List<String> getSchemaList() {
        return schemaList.stream().map(Schema::getName).collect(Collectors.toList());
    }

    public List<String> getSchemaTableList() {
        return schemaList.stream().flatMap(e -> e.getTables().stream()).map(Table::getSchemaTableName).collect(Collectors.toList());
    }

    public String getSchemaFieldName() {
        return "schema";
    }

    @Override
    public List<String> getTableList() {
        return null;
    }

    public abstract String getSchema();

    @Override
    public String getPrefix() {
        return "cdc";
    }

    @Override
    public String getSplit() {
        return "_";
    }

    private void initSchema() {
        SchemaMapping mapping = transProperties.getSchemaMapping();
        String database = mapping.getUpstreamSchema();
        Schema schema = new Schema();
    }


}
